@@ -4,6 +4,7 @@ from __future__ import division |
||
4 | 4 |
|
5 | 5 |
from django_logit import logit |
6 | 6 |
from django_response import response |
7 |
+from paginator import pagination |
|
7 | 8 |
|
8 | 9 |
from maintenance.models import ExpressCompanyInfo |
9 | 10 |
from utils.error.errno_utils import ExpressStatusCode |
@@ -48,9 +49,14 @@ def express_update(request): |
||
48 | 49 |
|
49 | 50 |
@logit |
50 | 51 |
def express_list(request): |
52 |
+ page = request.POST.get('page', 1) |
|
53 |
+ num = request.POST.get('num', 20) |
|
54 |
+ |
|
51 | 55 |
express = ExpressCompanyInfo.objects.filter(status=True) |
52 | 56 |
express = [exp.data for exp in express] |
57 |
+ express, left = pagination(express, page, num) |
|
53 | 58 |
|
54 | 59 |
return response(data={ |
55 | 60 |
'express': express, |
61 |
+ 'left': left, |
|
56 | 62 |
}) |
@@ -4,6 +4,7 @@ from __future__ import division |
||
4 | 4 |
|
5 | 5 |
from django_logit import logit |
6 | 6 |
from django_response import response |
7 |
+from paginator import pagination |
|
7 | 8 |
|
8 | 9 |
from maintenance.models import MaintenacePointInfo |
9 | 10 |
from utils.error.errno_utils import MaintenacePointStatusCode |
@@ -60,9 +61,14 @@ def maintenance_point_update(request): |
||
60 | 61 |
|
61 | 62 |
@logit |
62 | 63 |
def maintenance_point_list(request): |
64 |
+ page = request.POST.get('page', 1) |
|
65 |
+ num = request.POST.get('num', 20) |
|
66 |
+ |
|
63 | 67 |
points = MaintenacePointInfo.objects.filter(status=True) |
64 | 68 |
points = [point.data for point in points] |
69 |
+ points, left = pagination(points, page, num) |
|
65 | 70 |
|
66 | 71 |
return response(data={ |
67 | 72 |
'points': points, |
73 |
+ 'left': left, |
|
68 | 74 |
}) |
@@ -2,10 +2,13 @@ |
||
2 | 2 |
|
3 | 3 |
from __future__ import division |
4 | 4 |
|
5 |
+from django.conf import settings |
|
5 | 6 |
from django_logit import logit |
6 | 7 |
from django_response import response |
8 |
+from paginator import pagination |
|
7 | 9 |
|
8 | 10 |
from maintenance.models import MaintenaceInfo |
11 |
+from utils.admin_utils import is_maintenanceman |
|
9 | 12 |
from utils.error.errno_utils import MaintenaceStatusCode |
10 | 13 |
|
11 | 14 |
|
@@ -44,16 +47,27 @@ def maintenance_add(request): |
||
44 | 47 |
|
45 | 48 |
@logit |
46 | 49 |
def maintenance_delete(request): |
50 |
+ brand_id = request.POST.get('brand_id', settings.KODO_DEFAULT_BRAND_ID) |
|
47 | 51 |
maintenace_id = request.POST.get('maintenace_id', '') |
48 | 52 |
user_id = request.POST.get('user_id', '') |
49 | 53 |
|
50 |
- MaintenaceInfo.objects.filter(id=maintenace_id, user_id=user_id).update(status=False) |
|
54 |
+ try: |
|
55 |
+ maintenace = MaintenaceInfo.objects.get(id=maintenace_id, status=True) |
|
56 |
+ except MaintenaceInfo.DoesNotExist: |
|
57 |
+ return response(MaintenaceStatusCode.MAINTENACE_NOT_FOUND) |
|
58 |
+ |
|
59 |
+ if not is_maintenanceman(brand_id, user_id) and user_id != maintenace.user_id: |
|
60 |
+ return response(MaintenaceStatusCode.MAINTENACE_PERMISSION_DENIED) |
|
61 |
+ |
|
62 |
+ maintenace.status = False |
|
63 |
+ maintenace.save() |
|
51 | 64 |
|
52 | 65 |
return response() |
53 | 66 |
|
54 | 67 |
|
55 | 68 |
@logit |
56 | 69 |
def maintenance_update(request): |
70 |
+ brand_id = request.POST.get('brand_id', settings.KODO_DEFAULT_BRAND_ID) |
|
57 | 71 |
maintenace_id = request.POST.get('maintenace_id', '') |
58 | 72 |
user_id = request.POST.get('user_id', '') |
59 | 73 |
name = request.POST.get('name', '') |
@@ -68,10 +82,13 @@ def maintenance_update(request): |
||
68 | 82 |
maintenace_status = request.POST.get('maintenace_status', '') |
69 | 83 |
|
70 | 84 |
try: |
71 |
- maintenace = MaintenaceInfo.objects.get(id=maintenace_id, user_id=user_id, status=True) |
|
85 |
+ maintenace = MaintenaceInfo.objects.get(id=maintenace_id, status=True) |
|
72 | 86 |
except MaintenaceInfo.DoesNotExist: |
73 | 87 |
return response(MaintenaceStatusCode.MAINTENACE_NOT_FOUND) |
74 | 88 |
|
89 |
+ if not is_maintenanceman(brand_id, user_id) and user_id != maintenace.user_id: |
|
90 |
+ return response(MaintenaceStatusCode.MAINTENACE_PERMISSION_DENIED) |
|
91 |
+ |
|
75 | 92 |
if name: |
76 | 93 |
maintenace.name = name |
77 | 94 |
if phone: |
@@ -99,11 +116,32 @@ def maintenance_update(request): |
||
99 | 116 |
|
100 | 117 |
@logit |
101 | 118 |
def maintenance_list(request): |
119 |
+ brand_id = request.POST.get('brand_id', settings.KODO_DEFAULT_BRAND_ID) |
|
102 | 120 |
user_id = request.POST.get('user_id', '') |
121 |
+ page = request.POST.get('page', 1) |
|
122 |
+ num = request.POST.get('num', 20) |
|
103 | 123 |
|
104 |
- maintenaces = MaintenaceInfo.objects.filter(user_id=user_id, status=True) |
|
124 |
+ maintenaces = MaintenaceInfo.objects.filter(status=True) |
|
125 |
+ if not is_maintenanceman(brand_id, user_id): |
|
126 |
+ maintenaces = maintenaces.filter(user_id=user_id) |
|
105 | 127 |
maintenaces = [maintenace.data for maintenace in maintenaces] |
128 |
+ maintenaces, left = pagination(maintenaces, page, num) |
|
106 | 129 |
|
107 | 130 |
return response(data={ |
108 | 131 |
'maintenaces': maintenaces, |
132 |
+ 'left': left, |
|
133 |
+ }) |
|
134 |
+ |
|
135 |
+ |
|
136 |
+@logit |
|
137 |
+def maintenance_detail(request): |
|
138 |
+ maintenace_id = request.POST.get('maintenace_id', '') |
|
139 |
+ |
|
140 |
+ try: |
|
141 |
+ maintenace = MaintenaceInfo.objects.get(id=maintenace_id, status=True) |
|
142 |
+ except MaintenaceInfo.DoesNotExist: |
|
143 |
+ return response(MaintenaceStatusCode.MAINTENACE_NOT_FOUND) |
|
144 |
+ |
|
145 |
+ return response(data={ |
|
146 |
+ 'maintenace': maintenace.data, |
|
109 | 147 |
}) |
@@ -270,4 +270,5 @@ urlpatterns += [ |
||
270 | 270 |
url(r'^maintenance/delete$', maintenance_views.maintenance_delete, name='maintenance_delete'), |
271 | 271 |
url(r'^maintenance/update$', maintenance_views.maintenance_update, name='maintenance_update'), |
272 | 272 |
url(r'^maintenance/list$', maintenance_views.maintenance_list, name='maintenance_list'), |
273 |
+ url(r'^maintenance/detail$', maintenance_views.maintenance_detail, name='maintenance_detail'), |
|
273 | 274 |
] |
@@ -144,20 +144,6 @@ DATABASES = { |
||
144 | 144 |
# ALTER TABLE account_wechatinfo MODIFY COLUMN nickname VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; |
145 | 145 |
# account.UserInfo ==> nickname |
146 | 146 |
# ALTER TABLE account_userinfo MODIFY COLUMN nickname VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; |
147 |
- # group.GroupUserInfo ==> nickname |
|
148 |
- # ALTER TABLE group_groupuserinfo MODIFY COLUMN nickname VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL; |
|
149 |
- # group.GroupPhotoInfo ==> nickname |
|
150 |
- # ALTER TABLE group_groupphotoinfo MODIFY COLUMN nickname VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL; |
|
151 |
- # group.PhotoCommentInfo ==> nickname |
|
152 |
- # ALTER TABLE group_photocommentinfo MODIFY COLUMN nickname VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL; |
|
153 |
- # group.PhotoThumbUpInfo ==> nickname |
|
154 |
- # ALTER TABLE group_photothumbupinfo MODIFY COLUMN nickname VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL; |
|
155 |
- # group.UserMessageInfo ==> nickname |
|
156 |
- # ALTER TABLE message_usermessageinfo MODIFY COLUMN from_nickname VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL; |
|
157 |
- # |
|
158 |
- # Comment |
|
159 |
- # group.PhotoCommentInfo ==> comment |
|
160 |
- # ALTER TABLE group_photocommentinfo MODIFY COLUMN comment LONGTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; |
|
161 | 147 |
'charset': 'utf8mb4', |
162 | 148 |
}, |
163 | 149 |
} |
@@ -534,7 +534,7 @@ class MaintenancemanInfo(BaseModelMixin, SexModelMixin): |
||
534 | 534 |
|
535 | 535 |
class Meta: |
536 | 536 |
verbose_name = _(u'维修员信息') |
537 |
- verbose_name_plural = _(u'维修员信息信息') |
|
537 |
+ verbose_name_plural = _(u'维修员信息') |
|
538 | 538 |
|
539 | 539 |
unique_together = ( |
540 | 540 |
('maintenance_phone', 'brand_id'), |
@@ -1,18 +1,7 @@ |
||
1 | 1 |
# -*- coding: utf-8 -*- |
2 | 2 |
|
3 |
-from group.models import GroupInfo, GroupUserInfo |
|
4 |
-from TimeConvert import TimeConvert as tc |
|
3 |
+from mch.models import MaintenancemanInfo |
|
5 | 4 |
|
6 | 5 |
|
7 |
-def is_group_admin(group_id, admin_id): |
|
8 |
- return GroupUserInfo.objects.filter(group_id=group_id, user_id=admin_id, admin=True, admin_status=True, status=True).exists() |
|
9 |
- |
|
10 |
- |
|
11 |
-def is_group_subadmin(group_id, admin_id): |
|
12 |
- return GroupUserInfo.objects.filter(group_id=group_id, user_id=admin_id, subadmin=True, admin_status=True, status=True).exists() |
|
13 |
- |
|
14 |
- |
|
15 |
-def have_active_group(user_id): |
|
16 |
- groups = GroupUserInfo.objects.filter(user_id=user_id, subadmin=True, admin_status=True, status=True) |
|
17 |
- groupids = [group.group_id for group in groups] |
|
18 |
- return GroupInfo.objects.filter(group_id__in=groupids, group_closed=False, status=True, ended_at__gt=tc.utc_datetime()).exists() |
|
6 |
+def is_maintenanceman(brand_id, user_id): |
|
7 |
+ return MaintenancemanInfo.objects.filter(brand_id=brand_id, user_id=user_id, status=True).exists() |
@@ -121,6 +121,7 @@ class ExpressStatusCode(BaseStatusCode): |
||
121 | 121 |
class MaintenaceStatusCode(BaseStatusCode): |
122 | 122 |
""" 维修相关错误码 5080xx """ |
123 | 123 |
MAINTENACE_NOT_FOUND = StatusCodeField(508001, 'Maintenace Not Found', description=u'维修不存在') |
124 |
+ MAINTENACE_PERMISSION_DENIED = StatusCodeField(508002, 'Maintenace Permission Denied', description=u'维修权限不足') |
|
124 | 125 |
|
125 | 126 |
|
126 | 127 |
class AdministratorStatusCode(BaseStatusCode): |